/*
  将下面异步代码使用 Promise 的方法改进
  尽量用看上去像同步代码的方式
  setTimeout(function () {
    var a = 'hello'
    setTimeout(function () {
      var b = 'lagou'
      setTimeout(function () {
        var c = 'I ♥ U'
        console.log(a + b +c)
      }, 10)
    }, 10)
  }, 10)
*/

// 方案一 
new Promise((resolve, reject) => {
  setTimeout(function() {
    resolve('hello');
  }, 10);
}).then(value => {
  return new Promise((resolve, reject) => {
    setTimeout(function() {
      resolve(value + 'lagou');
    }, 10);
  })
}).then(value => {
  return new Promise((resolve, reject) => {
    setTimeout(function() {
      resolve(value + 'I ♥ U');
    }, 10);
  })
}).then(value => {
  console.log(value);
}).catch(err => {
  console.error(err);
});

// 方案二
function getInfo (x) {
  return new Promise((resolve, reject) => {
    setTimeout(function() {
      resolve(x);
    }, 10);
  })
}

getInfo('lagou')
.then(value => {
  return getInfo(value + 'jiaoyu');
})
.then(value => {
  return getInfo(value + 'I ❥(^_-) U')
})
.then(console.log)


